Ccay.Module.define("Ccay.example.ui.validate",function(page,$S){
	
	page.ready=function(){
		$("#validateDemo").ccayTab();
		addMethod();
		addClassRules();
	}
	
	page.init=function(){
		page.addMethod();
		page.addClassRules();
	};
	addMethod = function(){
		//添加一个新的验证方法.
		$.validator.addMethod(
			"customFun", 
			function(value){if(/^\d+$/.test(value)){return true} return false},
			 $i18n("ccay.common.validate.numeric") 
		);
	};
	addClassRules = function(){
		//增加组合验证类型
		$.validator.addClassRules("YourClassName",{  maxlength:10, customFun: true}); 
	}
	page.validate = function(form){
		$S(form).valid();
	}
	//手動校驗
	page.valida = function(){
		$S("#homeAddress1").valid();
	}
	
	//运行代码
	page.runDemo=function() {
		$("#demoMainPanel").html("<form id='demo' class='init ccay-form' action='#'> "
    	+ " <div><ul ><li  class='ccay-form-input'> "
    	+ $("#htmlTxt").val()
    	+ " <input type='button' class='button' value='validate' onclick='Ccay.example.ui.validate.validate(\"#demo\")'/>"
    	+ " </li></ul></div></form>");
		
		Ccay.UI.init("#demoMainPanel");
		try {
			if ($("#jsTxt").val() != null && $("#htmlTxt").val() != null) {
				eval($("#jsTxt").val());
			}
			if ( $("#htmlTxt").val() == "") {
				$("#demoMainPanel").html(eval($("#jsTxt").val()));
			}
		} catch (e) {
			alert(e);
		}
	};
});

